package cn.gson.crmdemo.controller.finance;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Emp;
import cn.gson.crmdemo.model.pojo.Reimbursement;
import cn.gson.crmdemo.model.service.BxService;
import cn.gson.crmdemo.model.vo.BxVo;

@Controller
public class BxConreoller {
	@Autowired
	BxService be;
	public Map<String,Object> yy(JSONArray selecthk,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selecthk);
		map.put("total",page.getTotal());
		return map;
	}
	@RequestMapping("bx")
	@ResponseBody
	public Map<String,Object>fkfp(Integer pageNum,Integer pasgeSize,String reimDate,Integer reimState,String reimName){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		Integer a = 0;
		if("".equals(reimName)||reimName==null) {
			a=0;
		}else if(!reimName.equals("")){
			 a=be.selectsqrcxy(reimName);
		}
	
		JSONArray selectfkfp=be.selectsp(reimDate,reimState,a);
			return yy(selectfkfp, page);
	
	}
	/**
	 * 申请人查询	
	 * @param a
	 * @param b
	 * @param c
	 * @param request
	 * @return
	 */@RequestMapping("bx-sqr")
		@ResponseBody
	public Map<String,Object> sqe(Integer pageNum,Integer pasgeSize,String reimDate,Integer reimState,HttpServletRequest request) {
		//分页
				Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
				//查询数据
				Emp emp = (Emp) request.getSession().getAttribute("emp");
				Integer a = emp.getEmpId();
				JSONArray selectfkfp=be.selectsp(reimDate,reimState,a);
					return yy(selectfkfp, page);
	}
	@RequestMapping("bx-xgzt")
	public String xgzt(int a,int b,String c,HttpServletRequest request) {
		Emp emp = (Emp) request.getSession().getAttribute("emp");
		c=emp.getEmpName();
		be.xgzt(a,b,c);
		return "redirect:bx?pageNum=1&pasgeSize=7";
		
	}
	@RequestMapping("bx-cxzt")
	public String cx(int a,int b,String c,HttpServletRequest request) {
		Emp emp = (Emp) request.getSession().getAttribute("emp");
		c=emp.getEmpName();
		be.xgzt(a,b,c);
		return  "redirect:bx-sqr?pageNum=1&pasgeSize=7&reimDate=&reimState=5";
		
	}
	//查询当前登录人
	@RequestMapping("cx-dlr")
	@ResponseBody
	public JSONArray selectsprcx(Integer a,HttpServletRequest request) {
		Emp emp = (Emp) request.getSession().getAttribute("emp");
		a=emp.getEmpId();
		return be.selectsprcx(a);
	}
	//根据状态查询
	@RequestMapping("bx-ztcx")
	@ResponseBody
	public Map<String,Object>selectzt(Integer pageNum,Integer pasgeSize,Integer a){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=be.selectzt(a);
		//创建Map集合
		return this.yy(selectfkfp, page);

	}
	
	//新增报销申请
	@RequestMapping("bx-add")
	public String addsqbx(BxVo bo) {
		be.addbx(bo);
		return "redirect:bx-sqr?pageNum=1&pasgeSize=7&reimDate=&reimState=5";
	}
	@RequestMapping("bxsq-xgzt")
	public String xgzt1(int a,int b) {
		be.xgzt1(a, b);
		return "redirect:bx?pageNum=1&pasgeSize=7";
	}
	@RequestMapping("bx-sprcx")
	@ResponseBody
	public JSONArray selectspr() {
		return be.selectspr();
	}
	//查询当前申请人
	@RequestMapping("bx-sqrcx")
	@ResponseBody
	public JSONArray selectsqr() {
		return be.selectsqr();
	}
	//模糊查询
	@RequestMapping("mhcx-sj")
	@ResponseBody
	public Map<String,Object>selectsqrq(Integer pageNum,Integer pasgeSize,String rq){
		
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=be.selectsqrq(rq);
		//创建Map集合
		return this.yy(selectfkfp, page);

	}
	/**
	 * 根据申请人查询
	 */
	@RequestMapping("mhcx-sqr")
	@ResponseBody
	public Map<String,Object>selectsqrcx(Integer pageNum,Integer pasgeSize,String b){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		int a=be.selectsqrcxy(b);
		JSONArray selectfkfp=be.selectsqrcx(a);
		//创建Map集合
		return this.yy(selectfkfp, page);

	}
	
}
